﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Text;
using QSHC.QSchedule.Web.Models;
using System.Linq;

namespace QSHC.QSchedule.Silverlight.Converters
{
    public class PreOrderAppointmentConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var appiontment = value as Appointment;
            var preOrderList = new StringBuilder();

            if (appiontment != null)
            {
                int i = 1;
                var count = appiontment.AppointmentDetails.Where(p => p.PreOrder.Type != 4).Count();
                foreach (var item in appiontment.AppointmentDetails.Where((p => p.PreOrder.Type != 4)))
                {
                    if(i != count)
                        preOrderList.Append(string.Format("   {0}\n", item.PreOrder.Name));
                    else
                        preOrderList.Append(string.Format("   {0}", item.PreOrder.Name));

                    i++;
                }

                return preOrderList.ToString();
            }
            else
            {
                return "";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
